﻿package controller {
	import flash.events.ProgressEvent;
	import model.utils.ModuleConfig;
	
	import flash.display.Stage;
	import org.puremvc.as3.interfaces.INotification;	
	import org.puremvc.as3.patterns.command.SimpleCommand;
	import org.puremvc.as3.interfaces.ICommand;
	
	import br.com.stimuli.loading.BulkLoader;

	/**
	 * @author Aleksey Lobanov
	 * Create and register proxies and mediators
	 */
	public class LoadStaticDataCommand extends SimpleCommand implements ICommand {
		
		private var _bulkLoader:BulkLoader;
		
		override public function execute(note : INotification) : void {
			_bulkLoader = new BulkLoader("xml loading");
			
			_bulkLoader.add(ModuleConfig.CORE_DATAS_PATH, { id:"core" } );
			
			_bulkLoader.addEventListener(BulkLoader.COMPLETE, onCompleteHandler);
			_bulkLoader.addEventListener(BulkLoader.PROGRESS, onProgressHandler);
			_bulkLoader.start();
			
		}
		
		private function onProgressHandler(evt:ProgressEvent):void {
			//trace("Loaded" , evt.bytesLoaded," of ",  evt.bytesTotal);
		}
		
		private function onCompleteHandler(evt:ProgressEvent):void {		
			
			
			sendNotification(ApplicationFacade.CORE_DATA_IS_LOAD, new XML(_bulkLoader.getText("core", true))); 
			_bulkLoader.clear();
			
			//request first stage size
			sendNotification( ApplicationFacade.DISPATCH_STAGE_RESIZE, null );
		}
	}
}